
<template>
  <div class="write-mood-page" :style="'padding-top:'+headHeight+'rpx;'">
 
    <head-back title="写个心情" @goBack="goBack"></head-back>

    <div class="content-box">
      <textarea type="text" v-model="textareaVal" class="write" placeholder="分享你此刻的想法..." maxlength="300"></textarea>
    </div>

    <!--发布-->
    <div class="btn" @click.sotp="addTopicArt">发布</div>
  </div>
</template>
<script>
    import * as api from '@/utils/api' ; 
    const app = getApp();
    import headBack from '@/components/head-back.vue' ;
  export default {
    onLoad(){

    },
    onShow: function () {

    },

    data () {
        return {
            headPadding:wx.getStorageSync('headPadding'), 
            headHeight:wx.getStorageSync('headHeight'), 
            userInfo:wx.getStorageSync('userInfo'),
            textareaVal:'',
        }
    },

    components:{
        headBack 
    },
    methods: {
        goBack(){ 
            setTimeout(()=>{
                wx.navigateBack({ delta: 1 });
            },300);
        }, 
        //发布文章
        addTopicArt(){
            let vm = this;
            if(vm.textareaVal==''){
                wx.showModal({
                    showCancel:false,
                    title: '提示',
                    content: '内容不能为空',
                    success (res) {
                        if (res.confirm) {
                        console.log('用户点击确定')
                        } 
                    }
                })
            }else{
                let body={
                    tag_ids:['2'],
                    user_id:wx.getStorageSync('userInfo').id,
                    content:vm.textareaVal 
                }
                api.addArtItem(body).then(res=>{
                  vm._data.textareaVal = '';
                    if(res.data.code==200){
                        wx.showToast({
                            title: '发布成功',
                            icon: 'success',
                            duration: 2000
                        })
                        setTimeout(()=>{
                            wx.navigateBack({
                                delta: 1
                            })
                        },2000)
                    }
                })
            } 
        },
    },
  }
</script>

<style lang="scss" scoped>
  .write-mood-page{
    width:100%;
    height:100%;
    background: #F1F2F7;
    font-size: 32rpx;

    .content-box{
      width: 100%;
      height: 560rpx;
      background: #ffffff;

      .write{
        width: 100%;
        height: 560rpx;
        min-height: 560rpx;
        max-height: 560rpx;
        padding: 28rpx 33rpx;
        box-sizing: border-box;
        color: #999999;
      }
    }

    //发布
    .btn{
      position: fixed;
      bottom: 0;
      width: 100%;
      height: 88rpx;
      text-align: center;
      line-height: 88rpx;
      font-size: 30rpx;
      color: #ffffff;
      background: linear-gradient(0deg,rgba(77,141,249,1),rgba(86,117,254,1));
      box-shadow: 0 2rpx 7rpx 0 rgba(82,127,252,0.48);
      &:active{
          opacity: .7;
      }
    }
  }

</style>
